<template>
  <transition name="slide">
    <music-list :title="title" :bg-image="bgImage" :songs="songs"></music-list>
  </transition>
</template>

<script type="text/ecmascript-6">
import { mapGetters } from 'vuex'
import { createSong } from 'common/js/song'
import MusicList from 'components/music-list/music-list'
import {songOfSingerId} from "api/index";

export default {
  data() {
    return {
      songs: []
    }
  },
  computed: {
    title() {
      return this.singer.name
    },
    bgImage() {
      return this.singer.avatar
    },
    ...mapGetters([
      'singer'
    ])
  },
  created() {
    this._getDetail()
  },
  methods: {
    _getDetail() {
      if(!this.singer.id){
        this.$router.push('/singer')
        return
      }
      songOfSingerId(this.singer.id).then((res) => {
        if (res) {
          //console.log(res)
          this.songs = this._normalizeSongs(res)
          //console.log(this.songs)
        }
      })
    },
    _normalizeSongs(list) {
      let ret = []
      list.forEach((item) => {
        if(item.id) {
          ret.push(createSong(item))
          //console.log(ret)
        }
      });
      return ret
    }
  },
  components: {
    MusicList
  }
};
</script>

<style lang="stylus" scoped rel="stylesheet/stylus">
@import '~common/stylus/variable';

.slide-enter-active, .slide-leave-active
    transition: all 0.3s

  .slide-enter, .slide-leave-to
    transform: translate3d(0, 100%, 0)

</style>
